Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all standardrb errors and warnings #168

Closed
wants to merge 6 commits into from
Closed

Conversation

abachman
Copy link
Member

@abachman abachman commented Jun 1, 2024

In order to establish a safe base for auto-formatting using editor-based tooling with the Standard formatter, I want to clean up all existing standardrb and standardrb-rails errors and warnings.

I did this in two stages:

  1. bundle exec standardrb --fix
  2. Manually fix everything that autoformat couldn't touch. This was mostly Rails problems.

This way we can add "Ruby Lint" as a required check for all Pull Requests going forward.

Comment on lines +63 to +64
$ docker compose run stocks bin/rails db:create
$ docker compose run stocks bin/rails test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, useful

Comment on lines -11 to +12
def show; end
def show
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the single lines aesthetically, but I'm not going to fight the standardrb defaults over it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D

Now you're feeling that "unconfigurable configuration" vibe.

@@ -1,5 +1,5 @@
class Classroom < ApplicationRecord
belongs_to :year
belongs_to :school
has_many :users
has_many :users, dependent: :nullify
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought through the alternative arguments to dependent: and I think this is the correct one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also suspect we may end up with a join model here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Yeah, I can see that

has_many :portfolio_stocks
has_many :orders
has_many :portfolio_stocks, dependent: :nullify
has_many :orders, dependent: :nullify
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels wrong to me because stocks should never be deleted. They should be moved to an inactive state instead. Maybe :restrict_with_error instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it.

"should never be deleted" will have a lot more interesting considerations in the future, but this is an easy fix now

has_many :portfolio_transactions
has_many :portfolio_stocks
has_many :portfolio_transactions, dependent: :destroy
has_many :portfolio_stocks, dependent: :destroy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may also be a candidate for restrict_with_error or restrict_with_exception

@h-m-m
Copy link
Collaborator

h-m-m commented Jun 1, 2024

I like autoformatters because they help me have a second chance to look at the code with a fresh perspective in addition to their other benefits. This looks good to me. I especially like all the README updates

@abachman
Copy link
Member Author

abachman commented Jun 1, 2024

This is something we can pick back up after the event. Closing for now, can reopen a new PR later.

@abachman abachman closed this Jun 1, 2024
@abachman abachman deleted the standardize-everything branch June 1, 2024 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants